package com.smalls.newvideotwo.util;

import android.animation.LayoutTransition;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.util.Log;
import android.view.animation.AnimationUtils;
import android.view.animation.LayoutAnimationController;
import android.view.animation.LinearInterpolator;

import com.smalls.newvideotwo.R;
import com.smalls.newvideotwo.utils.Constant;
import com.smalls.newvideotwo.view.SmoothScrollListView;

public class MyAnimation {
    private static String TAG = Constant.baddcoolio2tag? Constant.TAGPREFIXSTR + "MyAnimation":"MyAnimation";
    public LayoutAnimationController alphamLayoutAnimationController;
    private Context context = null;
    public LayoutAnimationController leftToRightController;
    public LayoutAnimationController mLayoutACLeftOut;
    public LayoutAnimationController mLayoutAnimationControllerXXX;
    public LayoutTransition mLayoutTransition;

    public MyAnimation(Context context) {
        this.context = context;
        initAimation();
    }

    private void initAimation() {
        ObjectAnimator defaultFadeOut = ObjectAnimator.ofFloat(null, "alpha", new float[]{1.0f, 0.0f});
        defaultFadeOut.setDuration(280);
        defaultFadeOut.setStartDelay(0);
        this.mLayoutTransition = new LayoutTransition();
        this.mLayoutTransition.setAnimator(1, null);
        this.mLayoutTransition.setStartDelay(1, 0);
        this.mLayoutTransition.setDuration(1, 300);
        this.mLayoutTransition.setInterpolator(1, new LinearInterpolator());
        this.mLayoutTransition.setAnimator(2, null);
        this.mLayoutTransition.setStartDelay(2, 0);
        this.mLayoutTransition.setDuration(2, 280);
        this.mLayoutTransition.setInterpolator(2, new LinearInterpolator());
        this.mLayoutAnimationControllerXXX = new LayoutAnimationController(AnimationUtils.loadAnimation(this.context, R.anim.xxxx));
        this.mLayoutAnimationControllerXXX.setOrder(0);
        this.mLayoutAnimationControllerXXX.setDelay(0.0f);
        this.mLayoutAnimationControllerXXX.setInterpolator(new LinearInterpolator());
        this.alphamLayoutAnimationController = new LayoutAnimationController(AnimationUtils.loadAnimation(this.context, R.anim.alpha_one));
        this.alphamLayoutAnimationController.setDelay(0.0f);
        this.alphamLayoutAnimationController.setOrder(0);
        this.alphamLayoutAnimationController.setInterpolator(new LinearInterpolator());
        this.mLayoutACLeftOut = new LayoutAnimationController(AnimationUtils.loadAnimation(this.context, R.anim.left_out));
        this.mLayoutACLeftOut.setDelay(0.0f);
        this.mLayoutACLeftOut.setOrder(0);
        this.mLayoutACLeftOut.setInterpolator(new LinearInterpolator());
        this.leftToRightController = new LayoutAnimationController(AnimationUtils.loadAnimation(this.context, R.anim.left_to_right_l));
        this.leftToRightController.setDelay(0.0f);
        this.leftToRightController.setOrder(0);
        this.leftToRightController.setInterpolator(new LinearInterpolator());
    }

    public boolean smoothScrollListViewUP(SmoothScrollListView scrollListView, int correntItemPosition) {
        Log.i(TAG, "MyAnimation-->smoothScrollListViewUP-->correntItemPosition=" + correntItemPosition);
        if (correntItemPosition == 0) {
            scrollListView.setSelection(scrollListView.getCount() - 1);
        }
        if (correntItemPosition == 1) {
            if (scrollListView.getChildAt(0).isFocused()) {
                return false;
            }
            scrollListView.smoothScrollBy(-scrollListView.itemHeight, scrollListView.scrollDuration);
            return false;
        } else if (correntItemPosition != 0) {
            scrollListView.smoothScrollBy(-scrollListView.itemHeight, scrollListView.scrollDuration);
            return false;
        } else if (scrollListView.onScrollTopListener == null) {
            return false;
        } else {
            scrollListView.onScrollTopListener.onScrollTop();
            return scrollListView.isScrollTop;
        }
    }

    public boolean smoothScrollListViewDown(SmoothScrollListView scrollListView, int correntItemPosition) {
        if (correntItemPosition == scrollListView.getCount() - 1) {
            scrollListView.setSelection(0);
        }
        Log.i(TAG, "MyAnimation-->smoothScrollListViewDown-->correntItemPosition=" + correntItemPosition);
        if (correntItemPosition == scrollListView.itemsCount - 2) {
            if (correntItemPosition != scrollListView.itemsCount - 1 || scrollListView.timer == null) {
                return false;
            }
            scrollListView.smoothScrollBy(scrollListView.itemHeight, scrollListView.scrollDuration);
            scrollListView.timer.cancel();
            scrollListView.timer = null;
            scrollListView.smoothScrollToButtom();
            return false;
        } else if (correntItemPosition == scrollListView.itemsCount - 1) {
            if (scrollListView.onScrollBottomListener != null) {
                scrollListView.onScrollBottomListener.onScrollBottom();
            }
            return true;
        } else {
            scrollListView.smoothScrollBy(scrollListView.itemHeight, scrollListView.scrollDuration);
            return false;
        }
    }
}
